package 书店销售管理系统;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Oracleconnection {
    public static Connection getConnection() {
        Connection conn = null;
        try {
            Class.forName("oracle.jdbc.driver.OracleDriver"); // 加载数据库驱动
            System.out.println("数据库驱动加载成功！"); // 输出的信息
            String url = "jdbc:oracle:thin:@localhost:1521:xe"; // 获取连接URL
            String user = "HR"; // 连接用户名
            String password = "123456"; // 连接密码
            conn = DriverManager.getConnection(url, user, password); // 获取数据库连接
            if (conn != null) {
                System.out.println("成功的与Oracle数据库建立连接！！");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return conn; // 返回Connection实例
    }

    public static void release(Connection conn, Statement ps, ResultSet rs) {
        try {
            if (rs != null) {
                rs.close();
            }
            if (ps != null) {
                ps.close();
            }
            if (conn != null) {
                conn.close();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        Connection conn = getConnection();
        release(conn, null, null);
    }
}